﻿using BIMBaseCS.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Resources.ResXFileRef;

namespace checc_baseTools
{
    internal class CheccConeSlope
    {
        public static GeRotMatrix CE单位矩阵(GePoint3d D矩阵原点, GePoint3d D矩阵X轴点, GePoint3d D矩阵Y轴点)
        {
            GeRotMatrix rMatrix = new GeRotMatrix();
            GeVec3d V矩阵原点 = new GeVec3d(D矩阵原点.x, D矩阵原点.y, D矩阵原点.z);
            GeVec3d V矩阵X轴点 = new GeVec3d(D矩阵X轴点.x, D矩阵X轴点.y, D矩阵X轴点.z);
            GeVec3d V矩阵Y轴点 = new GeVec3d(D矩阵Y轴点.x, D矩阵Y轴点.y, D矩阵Y轴点.z);

            GeVec3d X轴单位向量 = new GeVec3d();
            GeVec3d Y轴单位向量 = new GeVec3d();
            GeVec3d Z轴单位向量 = new GeVec3d();
            GeVec3d Dnum = new GeVec3d();

            //X轴单位向量
            Dnum = V矩阵X轴点 - V矩阵原点;
            //单位向量
            Dnum.normalize();
            //MessageBox.Show(Convert.ToString(DVector3d.Zero.Distance(Dnum)));
            X轴单位向量 = Dnum;

            //Y轴单位向量
            Dnum = V矩阵Y轴点 - V矩阵原点;
            //单位向量
            Dnum.normalize();
            //MessageBox.Show(Convert.ToString(DVector3d.Zero.Distance(Dnum)));
            Y轴单位向量 = Dnum;

            //Z轴单位向量
            Dnum = X轴单位向量 ^ Y轴单位向量;
            //单位向量
            Dnum.normalize();
            //MessageBox.Show(Convert.ToString(DVector3d.Zero.Distance(Dnum)));
            Z轴单位向量 = Dnum;

            GeVec3d DVX = new GeVec3d(X轴单位向量.x, Y轴单位向量.x, Z轴单位向量.x);
            GeVec3d DVY = new GeVec3d(X轴单位向量.y, Y轴单位向量.y, Z轴单位向量.y);
            GeVec3d DVZ = new GeVec3d(X轴单位向量.z, Y轴单位向量.z, Z轴单位向量.z);

            rMatrix = GeRotMatrix.createByRowVectors(DVX, DVY, DVZ);

            //MessageBox.Show(Convert.ToString(rMatrix.RowX.X + "/" + rMatrix.RowX.Y + "/" + rMatrix.RowX.Z));
            //MessageBox.Show(Convert.ToString(rMatrix.RowY.X + "/" + rMatrix.RowY.Y + "/" + rMatrix.RowY.Z));
            //MessageBox.Show(Convert.ToString(rMatrix.RowZ.X + "/" + rMatrix.RowZ.Y + "/" + rMatrix.RowZ.Z));

            return rMatrix;
        }


        /// <returns></returns>
        //public static IGeSolidBase CreateConePsolid(double basePrim, double baseSec, double topPrim, double topSec, double height, DgnModel dgnmodel1)
        //{
        //    IGeSolidBase pSolid = null;
        //    try
        //    {
        //        if (SolidUtil.RapidSolidCreate.MakeEllipticalConeBody(out pSolid, basePrim, baseSec, topPrim, topSec, height, modelRef1) == BentleyStatus.Success)
        //        {
        //            return pSolid;
        //        }
        //    }
        //    catch (Exception)
        //    {

        //    }
        //    return null;
        //}


        //绘制铺砌和截水墙
        //private static void CreatePaveAndCutoffWall_L()
        //{
        //    CheccConeSlopeData coneSlopeData = CheccConeSlopeData.Instance;
        //    double b = coneSlopeData.slope_ConeAxis * coneSlopeData.H_Cone_L;
        //    double a = coneSlopeData.slope_ConeBxis * coneSlopeData.H_Cone_L;
        //    //铺砌
        //    GeCurveArray curve = GeCurveArray.create(GeCurveArray.BoundaryType.Inner);
        //    //Bentley.GeometryNET.CurveVector curve = Bentley.GeometryNET.CurveVector.Create(Bentley.GeometryNET.CurveVector.BoundaryType.Inner);
        //    //靠近涵身边线
        //    IGeCurveBase line = IGeCurveBase.createSegment(new GeSegment3d(new GePoint3d(0, -(coneSlopeData.distance_L + coneSlopeData.disToCulvert), 0), new GePoint3d(0, coneSlopeData.distance_L + coneSlopeData.disToCulvert, 0)));
        //    curve.add(line);
        //    //CurvePrimitive line = CP_line(new DPoint3d(0, -(coneSlopeData.distance_L + coneSlopeData.disToCulvert), 0), new DPoint3d(0, coneSlopeData.distance_L + coneSlopeData.disToCulvert, 0));
        //    //curve.Add(line);
        //    //左洞大桩号圆弧
        //    IGeCurveBase arc1 = IGeCurveBase.createEllipse(new GeEllipse3d(new GePoint3d(0, -(coneSlopeData.distance_L + coneSlopeData.disToCulvert), 0), new GePoint3d(0, coneSlopeData.distance_L + coneSlopeData.disToCulvert, 0)));

        //    CurvePrimitive arc1 = CP_EllipseArc(new DPoint3d(0, coneSlopeData.distance_L + coneSlopeData.disToCulvert + b, 0), a, b, -Math.PI / 2.0, -Math.PI / 2.0, out DPoint3d arcEndPoint1, false);
        //    curve.Add(arc1);
        //    //左洞小桩号圆弧
        //    CurvePrimitive arc2 = CP_EllipseArc(new DPoint3d(0, -coneSlopeData.distance_L - coneSlopeData.disToCulvert - b, 0), a, b, Math.PI, -Math.PI / 2.0, out DPoint3d arcEndPoint2, true);
        //    //上边线
        //    DPoint3d ptside1 = new DPoint3d(arcEndPoint1.X - coneSlopeData.paveOffset_L, arcEndPoint1.Y, arcEndPoint1.Z);
        //    line = CP_line(arcEndPoint1, ptside1);
        //    curve.Add(line);
        //    //左边线
        //    DPoint3d ptside2 = new DPoint3d(arcEndPoint2.X - coneSlopeData.paveOffset_L, arcEndPoint2.Y, arcEndPoint2.Z);
        //    line = CP_line(ptside1, ptside2);
        //    curve.Add(line);
        //    //下边线
        //    line = CP_line(ptside2, arcEndPoint2);
        //    curve.Add(line);
        //    curve.Add(arc2);
        //    //DraftingElementSchema.ToElement(dgnmodel, curve, null).AddToModel();
        //    pave_L = SolidHelper.CreateExtrusionWithDir(curve, coneSlopeData.thickness_pave, coneSlopeData.paveLevelName, (int)coneSlopeData.paveSolidColor, (int)coneSlopeData.paveSolidLineStyle, 0, dgnmodel, new DVector3d(0, 0, -1));
        //    //pave_L.AddToModel();
        //    //截水墙
        //    Bentley.GeometryNET.CurveVector curveVector = Bentley.GeometryNET.CurveVector.Create(Bentley.GeometryNET.CurveVector.BoundaryType.Inner);
        //    ptside1 = new DPoint3d(ptside1.X, ptside1.Y, ptside1.Z - coneSlopeData.thickness_pave);
        //    ptside2 = new DPoint3d(ptside2.X, ptside2.Y, ptside2.Z - coneSlopeData.thickness_pave);
        //    line = CP_line(ptside1, ptside2);
        //    curveVector.Add(line);
        //    DPoint3d ptside3 = new DPoint3d(ptside2.X + coneSlopeData.W_CutoffWall, ptside2.Y, ptside2.Z);
        //    line = CP_line(ptside2, ptside3);
        //    curveVector.Add(line);
        //    DPoint3d ptside4 = new DPoint3d(ptside1.X + coneSlopeData.W_CutoffWall, ptside1.Y, ptside1.Z);
        //    line = CP_line(ptside3, ptside4);
        //    curveVector.Add(line);
        //    line = CP_line(ptside4, ptside1);
        //    curveVector.Add(line);
        //    cutoffWall_L = SolidHelper.CreateExtrusionWithDir(curveVector, coneSlopeData.H_CutoffWall, coneSlopeData.cutoffWallLevelName, (int)coneSlopeData.cutoffWallSolidColor, (int)coneSlopeData.cutoffWallSolidLineStyle, 0, dgnmodel, new DVector3d(0, 0, -1));
        //    //cutoffWall_L.AddToModel();
        //}

        //绘制左洞椎体
        //private static void CreateCone_L()
        //{
        //    //大桩号锥坡
        //    CheccConeSlopeData coneSlopeData = CheccConeSlopeData.Instance;
        //    double b = coneSlopeData.slope_ConeAxis * coneSlopeData.H_Cone_L;
        //    //创建正方体
        //    SolidKernelEntity slab_Hmax = SolidHelper.CreateSlab(500, 500, 500, modelRef);
        //    SolidKernelEntity slab_Vmax = SolidHelper.CreateSlab(500, 500, 500, modelRef);
        //    //平移   改变正方体的矩阵
        //    DTransform3d trans_Hmax = DTransform3d.FromTranslation(SolidHelper.MeterToUor(new DPoint3d(250, 0, 0))) * slab_Hmax.GetEntityTransform();
        //    slab_Hmax.SetEntityTransform(ref trans_Hmax);
        //    DTransform3d trans_Vmax = DTransform3d.FromTranslation(SolidHelper.MeterToUor(new DPoint3d(0, 250, 0))) * slab_Vmax.GetEntityTransform();
        //    slab_Vmax.SetEntityTransform(ref trans_Vmax);

        //    //剪切  正方体和圆锥相减
        //    SolidKernelEntity[] lstSlab_Hmax = new SolidKernelEntity[1];
        //    lstSlab_Hmax[0] = slab_Hmax;
        //    SolidKernelEntity pSolidforTrimMax = SolidHelper.CreateConePsolid(coneSlopeData.slope_ConeBxis * coneSlopeData.H_Cone_L, coneSlopeData.slope_ConeAxis * coneSlopeData.H_Cone_L, 0, 0, coneSlopeData.H_Cone_L, dgnmodel);
        //    SolidUtil.Modify.BodyBooleanSubtract(ref pSolidforTrimMax, ref lstSlab_Hmax, 1);


        //    SolidKernelEntity[] lstSlab_Vmax = new SolidKernelEntity[1];
        //    lstSlab_Vmax[0] = slab_Vmax;
        //    SolidUtil.Modify.BodyBooleanSubtract(ref pSolidforTrimMax, ref lstSlab_Vmax, 1);
        //    Convert1.BodyToElement(out cone_Lmax, pSolidforTrimMax, null, dgnmodel);
        //    SolidHelper.setElementByLevel(coneSlopeData.LevelName, (int)coneSlopeData.solidColor, (int)coneSlopeData.solidLineStyle, 0, cone_Lmax);


        //    //平移
        //    DTransform3d trans = DTransform3d.FromTranslation(SolidHelper.MeterToUor(new DPoint3d(0, coneSlopeData.distance_L + coneSlopeData.disToCulvert + b, coneSlopeData.H_Cone_L / 2.0)));
        //    cone_Lmax.ApplyTransform(new TransformInfo(trans));


        //    //小桩号锥坡
        //    SolidKernelEntity slab_Hmin = SolidHelper.CreateSlab(500, 500, 500, modelRef);
        //    SolidKernelEntity slab_Vmin = SolidHelper.CreateSlab(500, 500, 500, modelRef);
        //    //平移
        //    DTransform3d trans_Hmin = DTransform3d.FromTranslation(SolidHelper.MeterToUor(new DPoint3d(250, 0, 0))) * slab_Hmin.GetEntityTransform();
        //    slab_Hmin.SetEntityTransform(ref trans_Hmin);
        //    DTransform3d trans_Vmin = DTransform3d.FromTranslation(SolidHelper.MeterToUor(new DPoint3d(0, -250, 0))) * slab_Vmin.GetEntityTransform();
        //    slab_Vmin.SetEntityTransform(ref trans_Vmin);
        //    //剪切
        //    SolidKernelEntity[] lstSlab_Hmin = new SolidKernelEntity[1];
        //    lstSlab_Hmin[0] = slab_Hmin;
        //    SolidKernelEntity pSolidforTrimMin = SolidHelper.CreateConePsolid(coneSlopeData.slope_ConeBxis * coneSlopeData.H_Cone_L, coneSlopeData.slope_ConeAxis * coneSlopeData.H_Cone_L, 0, 0, coneSlopeData.H_Cone_L, dgnmodel);
        //    SolidUtil.Modify.BodyBooleanSubtract(ref pSolidforTrimMin, ref lstSlab_Hmin, 1);
        //    SolidKernelEntity[] lstSlab_Vmin = new SolidKernelEntity[1];
        //    lstSlab_Vmin[0] = slab_Vmin;
        //    SolidUtil.Modify.BodyBooleanSubtract(ref pSolidforTrimMin, ref lstSlab_Vmin, 1);
        //    Convert1.BodyToElement(out cone_Lmin, pSolidforTrimMin, null, dgnmodel);
        //    SolidHelper.setElementByLevel(coneSlopeData.LevelName, (int)coneSlopeData.solidColor, (int)coneSlopeData.solidLineStyle, 0, cone_Lmin);
        //    //平移
        //    DTransform3d transMin = DTransform3d.FromTranslation(SolidHelper.MeterToUor(new DPoint3d(0, -coneSlopeData.distance_L - coneSlopeData.disToCulvert - b, coneSlopeData.H_Cone_L / 2.0)));
        //    cone_Lmin.ApplyTransform(new TransformInfo(transMin));
        //    //cone_Lmin.AddToModel();
        //}

        ////椭圆圆弧  reverse==true 返回起点
        //private static CurvePrimitive CP_EllipseArc(GePoint3d cc, double R_a, double R_b, double startAngle, double sweepAngle, out GePoint3d outerPoint, bool reverse)
        //{
        //    GeEllipse3d arcEle1 = GeEllipse3d.createByPoints(cc, new GePoint3d(), new GePoint3d(), /*R_a , R_b ,*/ startAngle, sweepAngle);
        //    GeVec3d cv = new GeVec3d(arcEle1.vectorX.x, arcEle1.vectorX.y, arcEle1.vectorX.z);/*arcEle1.GetCurveVector();*/
        //    CurvePrimitive cp = cv.GetPrimitive(0);
        //    DPoint3d startPoint = new DPoint3d();
        //    DPoint3d endPoint = new DPoint3d();
        //    cp.GetStartEnd(out startPoint, out endPoint);
        //    if (reverse == true)
        //    {
        //        cp.GetStartEnd(out endPoint, out startPoint);
        //    }
        //    outerPoint = SolidHelper.UorToMeter(endPoint);
        //    return cp;
        //}
    }
}
